//
//  SettingViewController.m
//  BrushFace
//
//  Created by timer_q on 15/12/5.
//  Copyright © 2015年 Zzz. All rights reserved.
//

#import "SettingViewController.h"
#import "NavHelper.h"
#import "BorrowXieYiVCV.h"
#import "BrushXieYiVC.h"
#import "MeStatus.h"
#import "AppStatus.h"

@interface SettingViewController ()<UITableViewDelegate,UITableViewDataSource>
{
    UITableView *_tableView;
}
@end

@implementation SettingViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self UIConfig];
    [self dataInit];
    
}
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];

    [self.navBar setTitle:@"设置"];
    [self.navBar setLeftBtn:NAV_BAR_LEFT_BTN_TYPE_BLUE];
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];
}
- (void)viewDidDisappear:(BOOL)animated{
    [super viewDidDisappear:animated];
}

#pragma mark - data
- (void)dataInit{
    [_tableView reloadData];
}


#pragma mark - customUI
- (void)UIConfig{
    _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0,64, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height-49-44-20)];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    _tableView.backgroundColor = UIColorFromRGB(ColorValueForBackView_Gray);
    _tableView.showsVerticalScrollIndicator = NO;
    [self.view addSubview:_tableView];
    
    UIButton *logout = [[UIButton alloc] initWithFrame:CGRectMake(0, [UIScreen mainScreen].bounds.size.height-49, [UIScreen mainScreen].bounds.size.width, 49)];
    [logout setTitle:@"退出登录" forState:UIControlStateNormal];
    [logout setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [logout setBackgroundImage:[UIImage imageNamed:@"RedButtonBackView"] forState:UIControlStateNormal];
    [logout addTarget:self action:@selector(logoutButtonClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:logout];
}

#pragma mark - tableViewDelegate and DataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 3;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (section == 1) {
        return 2;
    }else{
        return 1;
    }
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 44;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 10;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *cellID = @"SettingCELL";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }
    if (indexPath.section == 0) {
        cell.textLabel.text = @"常见问题";
    }else if(indexPath.section == 1&&indexPath.row == 0){
        cell.textLabel.text = @"用户协议";
        
        UIView *line = [[UIView alloc] initWithFrame:CGRectMake(0, cell.frame.size.height-0.5, SCREEN_WIDTH, 0.5)];
        line.backgroundColor = _tableView.backgroundColor;
        [cell addSubview:line];
    }else if(indexPath.section == 1&&indexPath.row == 1){
        cell.textLabel.text = @"借贷协议";
    }else if(indexPath.section == 2){
        cell.textLabel.text = @"关于刷脸";
    }
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    if (indexPath.section == 0) {
        [NavHelper gotoQuestionVC];
    }else if(indexPath.section == 1&&indexPath.row == 0){
        BrushXieYiVC * _vc = [[BrushXieYiVC alloc]init];
        [_vc setHidesBottomBarWhenPushed:YES];
        [self.navigationController pushViewController:_vc animated:YES];
    }else if(indexPath.section == 1&&indexPath.row == 1){
        BorrowXieYiVCV * _vc = [[BorrowXieYiVCV alloc]init];
        [_vc setHidesBottomBarWhenPushed:YES];
        [self.navigationController pushViewController:_vc animated:YES];
    }else if(indexPath.section == 2){
        [NavHelper gotoAboutVC];
    }
}
#pragma mark - customMethods
- (void)logoutButtonClick:(UIButton *)sender{
    NSLog(@"退出登录");
    
    [self.navigationController popToRootViewControllerAnimated:NO];
    self.tabBarController.selectedIndex = 0;
    [[MeStatus sharedInstance] removeUserAccount];
    [AppStatus removeAddressBook];
    [NavHelper gotoHomeBrushVC];
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

@end
